package org.soc.timesheet.server.domain.service;

import java.util.List;
import org.soc.timesheet.domain.SubProjects;
import org.soc.timesheet.domain.Timesheet;
import org.soc.timesheet.domain.repository.TimesheetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TimesheetServiceImpl implements TimesheetService {

	
	
	@Override
	public void deleteBySubproject(int idSubProjects) {
		timesheetRepository.deleteBySubproject(idSubProjects);
	}

	@Override
	public List<Timesheet> findByIdSubProjectIn(List<SubProjects> subProjects) {
		// TODO Auto-generated method stub
		return timesheetRepository.findByIdSubProjectIn(subProjects); 
	}
	

	@Autowired
    TimesheetRepository timesheetRepository;

	public long countAllTimesheets() {
        return timesheetRepository.count();
    }

	public void deleteTimesheet(Timesheet timesheet) {
        timesheetRepository.delete(timesheet);
    }

	public Timesheet findTimesheet(String id) {
        return timesheetRepository.findOne(id);
    }

	public List<Timesheet> findAllTimesheets() {
        return timesheetRepository.findAll();
    }

	public List<Timesheet> findTimesheetEntries(int firstResult, int maxResults) {
        return timesheetRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveTimesheet(Timesheet timesheet) {
        timesheetRepository.save(timesheet);
    }

	public Timesheet updateTimesheet(Timesheet timesheet) {
        return timesheetRepository.save(timesheet);
    }
}
